//
//  HavingSalesViewController.m
//  1243
//
//  Created by 洛水寒 on 16/5/24.
//  Copyright © 2016年 1243. All rights reserved.
//

#import "HavingSalesViewController.h"
#import "NetWorkTools.h"//网络请求


@interface HavingSalesViewController ()

@property (weak, nonatomic) IBOutlet UILabel *couponID;//编码
@property (weak, nonatomic) IBOutlet UILabel *num;//购买数量
@property (weak, nonatomic) IBOutlet UILabel *price;//购买价格
@property (weak, nonatomic) IBOutlet UILabel *totalMoney;//总计金额
@property (weak, nonatomic) IBOutlet UILabel *ownNum;//拥有数量

@end

@implementation HavingSalesViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    self.title = @"进行出售";
    
    //赋值
    [self setValue];
}

- (void)setValue{
    _couponID.text = _model.UserName;
    _num.text = [NSString stringWithFormat:@"%@", _model.TradeQty];
    _price.text = [NSString stringWithFormat:@"%@", _model.TradePrice];
    _totalMoney.text = [NSString stringWithFormat:@"%.2f", [_num.text intValue] * [_price.text floatValue]];
    if ([_ownNumString isEqualToString:@"(null)"]) {
        _ownNum.text = @"0";
    }else{
        _ownNum.text = _ownNumString;
    }
}

//确认出售
- (IBAction)confirmedSale:(id)sender {
    //网络请求
    [self requestSell];
}
- (void)requestSell{
    NSDictionary *dict = [ReadLoginData readLoginData];
    
    NSString *TradeUserId = [dict objectForKey:@"Number"];
    NSNumber *TradeId = _model.Id;
    NSString *TradeQty = _num.text;
    NSString *TradePrice = _price.text;
    NSString *PayMoney = _totalMoney.text;
    
    
    
    NSDictionary *params = @{
                             //
                             @"TradeUserId":TradeUserId,
                             @"TradeId":TradeId,
                             @"TradeQty":TradeQty,
                             @"TradePrice":TradePrice,
                             @"PayMoney":PayMoney
                             };
    
    [[NetWorkTools sharedNetWorkTools] OtherobjectWithURLDict:params AndMenthodName:@"SellTicket" completeBlock:^(id object) {
        
        
        //提示框
        UIAlertView *message = [[UIAlertView alloc] initWithTitle:object[@"Message"] message:nil delegate:self cancelButtonTitle:@"确定" otherButtonTitles: nil];
        NSLog(@"%@", object[@"Message"]);
        [message show];
    }];
}








- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
@end
